<?php
include('includes/connexion.php');
$adminmanager = new AdminManager($connexion);
$elevemanager = new EleveManager($connexion);
session_start();
include('includes/secu.php');

$resultatmanager = new ResultatManager($connexion);
$testmanager = new TestManager($connexion);
$reponsemanager = new ReponseManager($connexion);
$exercicemanager = new ExerciceManager($connexion);
$questionmanager = new QuestionManager($connexion);

$idEleve = $resultatmanager->get($_GET['id'])->idRefEleve();
$idTest = $resultatmanager->get($_GET['id'])->idRefTest();
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <title>Tables Advanced - Target Admin</title>

  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">

  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,700italic,400,600,700">
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,300,700">
  <link rel="stylesheet" href="./css/font-awesome.min.css">
  <link rel="stylesheet" href="./js/libs/css/ui-lightness/jquery-ui-1.9.2.custom.min.css">
  <link rel="stylesheet" href="./css/bootstrap.min.css">

  <!-- Plugin CSS -->
  <link rel="stylesheet" href="./js/plugins/icheck/skins/minimal/blue.css">
  <link rel="stylesheet" href="js/plugins/select2/select2.css">
  <link rel="stylesheet" href="js/plugins/datepicker/datepicker.css">
  <link rel="stylesheet" href="js/plugins/simplecolorpicker/jquery.simplecolorpicker.css">
  <link rel="stylesheet" href="js/plugins/timepicker/bootstrap-timepicker.css">
  <link rel="stylesheet" href="js/plugins/fileupload/bootstrap-fileupload.css">
  
  <!-- App CSS -->
  <link rel="stylesheet" href="./css/target-admin.css">
  <link rel="stylesheet" href="./css/custom.css">


  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
  <![endif]-->
</head>

<body>

<?php include('includes/navbar.php'); ?>

<?php include('includes/mainbar.php'); ?>

<div class="container">

  <div class="content">

    <div class="content-container">
	<br><br>
<form action="impr_rapport_eleve.php" method="post">
<input name="id" value="<?php echo $_GET['id']; ?>" hidden />
      <div class="content-header">
        <h2 class="content-header-title">Generation du rapport de <?php echo $elevemanager->get($idEleve)->prenom()." ".$elevemanager->get($idEleve)->nom()." pour ".$testmanager->get($idTest)->intitule(); ?></h2>
      </div> <!-- /.content-header --> 

      <div class="row">

        <div class="col-md-12">

<?php 	foreach($resultatmanager->ListExercice($idEleve, $idTest) as $ex)
		{ ?>
        
        
	<?php	$exo = $exercicemanager->get($ex);
			if($exo->idRefExemple() == 0)
			{
				echo "<h2>".$exo->intitule()." (".$resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest)[0]->temps()."/".$exo->duree_seconde()."sec):</h2>";

				$reponseJuste = 0;
				foreach($resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest) as $res)
				{
					if($reponsemanager->get($res->idRefReponse())->correcte() == 1){
						$reponseJuste++;
					}
				}
				
				$rapidite = $resultatmanager->getByExerciceEleveTest($ex,$idEleve,$idTest)[0]->temps() / $exo->duree_seconde();
				$rapidite *= 100;
				
				$txRapidite = 0;
				foreach($resultatmanager->getByExercice($ex) as $res)
				{
					$txRapidite += $res->temps();
				}
				$txRapidite /= sizeof($resultatmanager->getByExercice($ex));
				$txRapidite /= $exo->duree_seconde();
				$txRapidite *= 100;
				
				$reponseRepondu = sizeof($resultatmanager->getQuestion($ex, $idEleve));
?>        
        	<div class="table-responsive">
              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="false"
                data-search="false"
                data-length-change="true"
                data-paginate="false"
              >
                  <thead>
                    <tr>
                      <th data-filterable="false" data-sortable="false" data-direction="desc">Question</th>
                      <th data-filterable="false">Réponses</th>
                    </tr>
                  </thead>
                  <tfoot>
                  <tr>
                  <td><?php echo "Réponse juste : <b>".number_format(($reponseJuste/$exercicemanager->getNbReponseJuste($ex))*100,2) ."%</b> sur une moyenne de ".number_format($resultatmanager->TxReponseCorrecte($ex),2)."%<br>";
				  echo "Question traitée : <b>".number_format(($reponseRepondu/$exercicemanager->getNbQuestion($ex))*100,2) ."%</b><br>";
				  ?></td>
                  <td><?php echo "Rapidité : <b>".number_format($rapidite,2)."%</b> sur une moyenne de ".number_format($txRapidite,2)."%"; ?></td>
                  </tr>
                  </tfoot>
                  <tbody>
<?php foreach($questionmanager->getByExercice($ex) as $quest){ ?>
                    <tr>
                      <td><?php echo $quest->contenu(); ?></td>
                      <td><?php
                      foreach($reponsemanager->getByQuestion($quest->id()) as $rep)
						{
							if($rep->correcte() == 1){ echo "*";}
							echo $rep->contenu()."<br>";
						}
					?></td>
                    </tr>
<?php } ?>
                  </tbody>
                </table>
<?php } } ?>    
			</div> <!-- /.table-responsive -->           
        </div> <!-- /.col -->

      </div> <!-- /.row -->
                <?php if($_SESSION['Admin']->idRefCollege() == NULL){?>
                <textarea style='width:100%; height:100px;' name="<?php echo $_GET['id']; ?>"></textarea>
                <input type="submit" value="Generer"/></form>
                <?php } ?>
    </div> <!-- /.content-container -->
      
  </div> <!-- /.content -->

</div> <!-- /.container -->


<?php include('includes/footer.php'); ?>

  <script src="./js/libs/jquery-1.10.1.min.js"></script>
  <script src="./js/libs/jquery-ui-1.9.2.custom.min.js"></script>
  <script src="./js/libs/bootstrap.min.js"></script>

  <!--[if lt IE 9]>
  <script src="./js/libs/excanvas.compiled.js"></script>
  <![endif]-->
  
  <!-- Plugin JS -->
  <script src="./js/plugins/datatables/jquery.dataTables.min.js"></script>
  <script src="./js/plugins/datatables/DT_bootstrap.js"></script>
  <script src="./js/plugins/tableCheckable/jquery.tableCheckable.js"></script>
  <script src="./js/plugins/icheck/jquery.icheck.min.js"></script>

  <!-- App JS -->
  <script src="./js/target-admin.js"></script>
  


  
</body>
</html>